﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.XtraGauges.Base;
using System.Xml;
using ZX.Web.UI.Controls;
using ZX.CRM.Bussiness;
using System.Data;
using System.IO;
using System.Text;

namespace ZX.WebApp.DeskTop.DeskTopItem
{
    public partial class BackMoneyCircleReport : BasePage
    {
        BCrmReport bll = new BCrmReport();
        string strPowerType = "";
        string dateType = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            dateType = this.GetStringFromQueryString("DateType", "");
            strPowerType = this.GetStringFromQueryString("PowerType", "");

            if (strPowerType == "")
                strPowerType = "0";
            //0:本月   1：本季度   2：本年
            if (string.IsNullOrEmpty(dateType)) 
                dateType = "0";

            LoadData(int.Parse(dateType));
        }
        private void LoadData(int strLoadType)
        {
            DataTable dt = bll.ReturnCircleBackMondyReport(this.UserId.ToString(), int.Parse(strPowerType), strLoadType);
            decimal strMaxValue = decimal.Parse(dt.Rows[0][0].ToString());  //目标
            decimal strValue = decimal.Parse(dt.Rows[0][1].ToString()); //结果
            decimal firstData = strMaxValue * (decimal)0.1;
            decimal secondData = (strMaxValue - firstData) * (decimal)0.8;
            //decimal thirdData = (strMaxValue - firstData - secondData);
            this.lblMuBiao.InnerText = strMaxValue.ToString();
            this.lblJieGuo.InnerText = strValue.ToString();

            string strTemp = "";
            strTemp += @"<XtraSerializer version='1.0' application='IGaugeContainer'>
                      <property name='LayoutInterval'>6</property>
                      <property name='LayoutPadding'>6</property>
                      <property name='AutoLayout'>true</property>
                      <property name='Items' iskey='true' value='5'>
                        <property name='Item1' isnull='true' iskey='true'>
                          <property name='Name'>circularGauge11</property>
                          <property name='ParentCollectionName'>Gauges</property>
                          <property name='TypeNameEx'>CircularGauge</property>
                          <property name='OptionsToolTip' isnull='true' iskey='true'>
                            <property name='TooltipTitle' />
                            <property name='TooltipIconType'>None</property>
                            <property name='Tooltip' />
                            <property name='TooltipFormat'>{1:F2}</property>
                            <property name='TooltipTitleFormat' />
                          </property>
                          <property name='ParentName' />
                          <property name='ProportionalStretch'>true</property>
                          <property name='Bounds'>@1,X=6@1,Y=6@3,Width=248@3,Height=248</property>
                        </property>
                        <property name='Item2' isnull='true' iskey='true'>
                          <property name='RescalingBestValues'>false</property>
                          <property name='RescalingThresholdMax'>0.05</property>
                          <property name='MinorTickmark' isnull='true' iskey='true'>
                            <property name='ShapeScale'>1, 1</property>
                            <property name='ShowLast'>true</property>
                            <property name='ShapeOffset'>-8</property>
                            <property name='ShowTick'>true</property>
                            <property name='ShowFirst'>true</property>
                            <property name='ShapeType'>Circular_Style26_2</property>
                          </property>
                          <property name='MajorTickmark' isnull='true' iskey='true'>
                            <property name='ShapeType'>Circular_Style26_1</property>
                            <property name='ShapeOffset'>-14</property>
                            <property name='ShapeScale'>1, 1</property>
                            <property name='ShowLast'>true</property>
                            <property name='ShowFirst'>true</property>
                            <property name='ShowTick'>true</property>
                            <property name='FormatString'>{0:F0}</property>
                            <property name='TextOffset'>-25</property>
                            <property name='ShowText'>true</property>
                            <property name='Multiplier'>1</property>
                            <property name='Addend'>0</property>
                            <property name='TextOrientation'>LeftToRight</property>
                            <property name='AllowTickOverlap'>false</property>
                          </property>
                          <property name='MinorTickCount'>4</property>
                          <property name='EndAngle'>60</property>
                          <property name='StartAngle'>-240</property>
                          <property name='MinValue'>0</property>
                          <property name='RescalingThresholdMin'>0.05</property>
                          <property name='MaxValue'>" + strMaxValue.ToString() + "</property>";
            strTemp += @"<property name='MajorTickCount'>11</property>
                          <property name='ParentCollectionName'>Scales</property>
                          <property name='ParentName'>circularGauge11</property>
                          <property name='BoundElementName' isnull='true' />
                          <property name='Name'>scale1</property>
                          <property name='TypeNameEx'>ArcScaleComponent</property>
                          <property name='Ranges' iskey='true' value='3'>
                            <property name='Item1' isnull='true' iskey='true'>
                              <property name='EndValue'>" + firstData.ToString() + "</property>" +
                                "<property name='AppearanceRange' isnull='true' iskey='true'>" +
                                "<property name='BorderWidth'>0</property>" +
                                "<property name='ContentBrush' isnull='true' iskey='true'>" +
                                  "<property name='Color'>158, 201, 104</property>" +
                                "</property>" +
                                "<property name='BorderBrush' isnull='true' iskey='true' />" +
                              "</property>" +
                              "<property name='StartThickness'>14</property>" +
                              "<property name='ShapeOffset'>0</property>" +
                              "<property name='EndThickness'>14</property>" +
                              "<property name='EndPercent' isnull='true' />" +
                              "<property name='StartPercent' isnull='true' />" +
                              "<property name='StartValue'>0</property>" +
                              "<property name='Name'>Range0</property>" +
                            "</property>" +
                            "<property name='Item2' isnull='true' iskey='true'>" +
                              "<property name='EndValue'>" + secondData.ToString() + "</property>";
            strTemp += @"<property name='AppearanceRange' isnull='true' iskey='true'>
                                <property name='BorderWidth'>0</property>
                                <property name='ContentBrush' isnull='true' iskey='true'>
                                  <property name='Color'>158, 201, 104</property>
                                </property>
                                <property name='BorderBrush' isnull='true' iskey='true' />
                              </property>
                              <property name='StartThickness'>14</property>
                              <property name='ShapeOffset'>0</property>
                              <property name='EndThickness'>14</property>
                              <property name='EndPercent' isnull='true' />
                              <property name='StartPercent' isnull='true' />
                              <property name='StartValue'>" + firstData.ToString() + "</property>" +
                            "<property name='Name'>Range1</property>" +
                            "</property>" +
                            "<property name='Item3' isnull='true' iskey='true'>" +
                              "<property name='EndValue'>" + strMaxValue.ToString() + "</property>" +
                                "<property name='AppearanceRange' isnull='true' iskey='true'>" +
                                "<property name='BorderWidth'>0</property>" +
                                "<property name='ContentBrush' isnull='true' iskey='true'>" +
                                  "<property name='Color'>158, 201, 104</property>" +
                                "</property>" +
                                "<property name='BorderBrush' isnull='true' iskey='true' />" +
                              "</property>" +
                              "<property name='StartThickness'>14</property>" +
                              "<property name='ShapeOffset'>0</property>" +
                              "<property name='EndThickness'>14</property>" +
                              "<property name='EndPercent' isnull='true' />" +
                              "<property name='StartPercent' isnull='true' />" +
                              "<property name='StartValue'>" + secondData.ToString() + "</property>";
            strTemp += @"<property name='Name'>Range2</property>
                            </property>
                          </property>
                          <property name='Labels' iskey='true' value='0' />
                          <property name='Enabled' isnull='true' iskey='true' />
                          <property name='ZOrder'>0</property>
                          <property name='Shader' isnull='true' iskey='true'>
                            <property name='TypeTag'>Empty</property>
                          </property>
                          <property name='RadiusY'>99</property>
                          <property name='AppearanceMinorTickmark' isnull='true' iskey='true'>
                            <property name='BorderWidth'>0</property>
                            <property name='ContentBrush' isnull='true' iskey='true'>
                              <property name='Color'>White</property>
                            </property>
                            <property name='BorderBrush' isnull='true' iskey='true'>
                              <property name='Color'>White</property>
                            </property>
                          </property>
                          <property name='Appearance' isnull='true' iskey='true'>
                            <property name='Width'>0</property>
                            <property name='Brush' isnull='true' iskey='true' />
                          </property>
                          <property name='AppearanceTickmarkText' isnull='true' iskey='true'>
                            <property name='Format' isnull='true' iskey='true'>
                              <property name='Trimming'>Character</property>
                              <property name='FormatFlags'>NoClip</property>
                              <property name='Alignment'>Center</property>
                              <property name='LineAlignment'>Center</property>
                            </property>
                            <property name='TextBrush' isnull='true' iskey='true'>
                              <property name='Color'>72, 78, 90</property>
                            </property>
                            <property name='Font'>Tahoma, 9pt</property>
                            <property name='Spacing'>0, 0, 0, 0</property>
                          </property>
                          <property name='AppearanceMajorTickmark' isnull='true' iskey='true'>
                            <property name='BorderWidth'>0</property>
                            <property name='ContentBrush' isnull='true' iskey='true'>
                              <property name='Color'>White</property>
                            </property>
                            <property name='BorderBrush' isnull='true' iskey='true'>
                              <property name='Color'>White</property>
                            </property>
                          </property>
                          <property name='AppearanceTickmarkTextBackground' isnull='true' iskey='true'>
                            <property name='BorderWidth'>0</property>
                            <property name='ContentBrush' isnull='true' iskey='true' />
                            <property name='BorderBrush' isnull='true' iskey='true' />
                          </property>
                          <property name='AppearanceScale' isnull='true' iskey='true'>
                            <property name='Width'>0</property>
                            <property name='Brush' isnull='true' iskey='true' />
                          </property>
                          <property name='RadiusX'>101</property>
                          <property name='Center'>125, 125</property>
                          <property name='AutoRescaling'>false</property>
                          <property name='Value'>" + strValue.ToString() + "</property>";
            strTemp += @"</property>
                        <property name='Item3' isnull='true' iskey='true'>
                          <property name='BoundElementName'>scale1</property>
                          <property name='Shader' isnull='true' iskey='true'>
                            <property name='TypeTag'>Empty</property>
                          </property>
                          <property name='Enabled' isnull='true' iskey='true' />
                          <property name='Name'>bg</property>
                          <property name='ParentCollectionName'>BackgroundLayers</property>
                          <property name='ParentName'>circularGauge11</property>
                          <property name='TypeNameEx'>ArcScaleBackgroundLayerComponent</property>
                          <property name='ShapeType'>CircularFull_Style26</property>
                          <property name='Size'>@3,Width=250@3,Height=250</property>
                          <property name='ZOrder'>1000</property>
                          <property name='ScaleCenterPos'>0.5, 0.512</property>
                        </property>
                        <property name='Item4' isnull='true' iskey='true'>
                          <property name='ParentCollectionName'>Needles</property>
                          <property name='Name'>needle</property>
                          <property name='Value' isnull='true' />
                          <property name='Enabled' isnull='true' iskey='true' />
                          <property name='BoundElementName'>scale1</property>
                          <property name='ParentName'>circularGauge11</property>
                          <property name='ZOrder'>-50</property>
                          <property name='TypeNameEx'>ArcScaleNeedleComponent</property>
                          <property name='EndOffset'>25</property>
                          <property name='StartOffset'>0</property>
                          <property name='Shader' isnull='true' iskey='true'>
                            <property name='TypeTag'>Empty</property>
                          </property>
                          <property name='ShapeType'>CircularFull_Style26</property>
                        </property>
                        <property name='Item5' isnull='true' iskey='true'>
                          <property name='BoundElementName'>scale1</property>
                          <property name='Shader' isnull='true' iskey='true'>
                            <property name='TypeTag'>Empty</property>
                          </property>
                          <property name='Enabled' isnull='true' iskey='true' />
                          <property name='Name'>cGauge1_SpindleCap1</property>
                          <property name='ParentCollectionName'>SpindleCaps</property>
                          <property name='ParentName'>circularGauge11</property>
                          <property name='TypeNameEx'>ArcScaleSpindleCapComponent</property>
                          <property name='ZOrder'>-100</property>
                          <property name='Size'>@2,Width=25@2,Height=25</property>
                          <property name='ShapeType'>CircularFull_Style26</property>
                        </property>
                      </property>
                      <property name='SizeEx'>@3,Width=210@3,Height=200</property>
                    </XtraSerializer>";
            byte[] arrbyte = Encoding.UTF8.GetBytes(strTemp);
            MemoryStream stream = new MemoryStream(arrbyte);
            GaugeContainer.ForceClearOnRestore = true;
            GaugeContainer.RestoreLayoutFromStream(stream);

            /*XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(Server.MapPath('~/App_Data/Styles/' + (string)style.Value));
            xmlDoc.SelectSingleNode('//XtraSerializer/property[@name='Items']/property[@name='Item2']/property[@name='MaxValue']').InnerXml = strMaxValue.ToString();
            xmlDoc.SelectSingleNode('//XtraSerializer/property[@name='Items']/property[@name='Item2']/property[@name='Ranges']/property[@name='Item1']/property[@name='EndValue']').InnerXml = firstData.ToString();
            xmlDoc.SelectSingleNode('//XtraSerializer/property[@name='Items']/property[@name='Item2']/property[@name='Ranges']/property[@name='Item2']/property[@name='StartValue']').InnerXml = firstData.ToString();
            xmlDoc.SelectSingleNode('//XtraSerializer/property[@name='Items']/property[@name='Item2']/property[@name='Ranges']/property[@name='Item2']/property[@name='EndValue']').InnerXml = secondData.ToString();
            xmlDoc.SelectSingleNode('//XtraSerializer/property[@name='Items']/property[@name='Item2']/property[@name='Ranges']/property[@name='Item3']/property[@name='StartValue']').InnerXml = secondData.ToString();
            xmlDoc.SelectSingleNode('//XtraSerializer/property[@name='Items']/property[@name='Item2']/property[@name='Ranges']/property[@name='Item3']/property[@name='EndValue']').InnerXml = strMaxValue.ToString();
            xmlDoc.SelectSingleNode('//XtraSerializer/property[@name='Items']/property[@name='Item2']/property[@name='Value']').InnerXml = strValue.ToString();
            xmlDoc.Save(Server.MapPath('~/App_Data/Styles/' + (string)style.Value));
            GaugeContainer.ForceClearOnRestore = true;
            GaugeContainer.RestoreLayoutFromXml(MapPath('~/App_Data/Styles/' + (string)style.Value));*/
        }

        protected IGaugeContainer GaugeContainer
        {
            get { return gaugeControl as IGaugeContainer; }
        }
    }
}